/**
 * 部门选择js切换效果
 */
$("#dropdown li a").on("click", function() {
	var department_name = $(this).text();
	$("a.dropdown-button.btn").text(department_name);
	var department_id = $(this).attr("department-id");
	$("input#departmentId").attr("value", department_id);
});

/**
 * 选择部门时通过ajax获取部门的json数据
 * 并且将返回的json数据显示到修改页面上
 */
$("div.collapsible-header").on("click", function() {
	var department_id = $(this).attr("department-id");
	$.ajax({
		async: false,
		url: "resultDepartmentJSON.action",
		data: {id:department_id},
		type: "POST",
		dataType: "json",
		success: function(department) {
//			var department = $.parseJSON(json);
			//设置部门ID
			$("input#id").attr("value", department.id);
			//设置上级部门名称
			if (department.superiorDepartmentName != null) {
				$("input#superiorDepartmentId").attr("value", department.superiorDepartmentName);
            } else {
                $("input#superiorDepartmentId").attr("value", "无");
            }
			//设置部门名称
			$("input#name").val(department.name);
			$("input#name").next().attr("class", "active");
			//设置部门描述
			$("textarea#description").html(department.description);
			$("textarea#description").next().attr("class", "active");
			
			//设置删除按钮href属性
			$("#delet-department-btn").attr("href", "deleteDepartment.action?id=" + department.id);
		}
	});
});